#include"tsubtitle.h"

TTime::TTime(void)
{

	sec = 0;
	
	min = 0;
	
	hour = 0;
	
}

TTime::TTime(int sec1, int min1, int h1)
{
	sec = sec1;
	min = min1;
	hour = h1;
	
//	Normalice();
}

TTime::TTime(const TTime &t)
{
	sec = t.sec;
	min = t.min;
	hour = t.hour;
}
	
TTime::~TTime(void)
{

	sec = 0;
	min = 0;
	hour = 0;
}

TTime& TTime::operator=(const TTime &t)
{
	if(this != &t)
	{
		sec = t.sec;
		min = t.min;
		hour = t.hour;
	}
	
	return (*this);
}

void TTime::SetTime(int sec1, int min1, int h1)
{
	sec = sec1;
	min = min1;
	hour = h1;
	
//	Normalice();
}

void TTime::SetTimeMin(int min1)
{
	min = min1;
}

void TTime::SetTimeHour(int h1)
{
	hour = h1;
	
}

int TTime::GetSec(void) const
{
	return sec;
}

int TTime::GetMin(void) const
{
	return min;
}

int TTime::GetHour(void) const
{
	return hour;
}

bool TTime::operator==(const TTime &t) const
{
	return (sec == t.sec &&
			min == t.min &&
			hour == t.hour);
}

bool TTime::operator!=(const TTime &t) const
{

	return (sec != t.sec &&
			min != t.min &&
			hour != t.hour);
}

bool TTime::operator>(const TTime &t) const
{
	bool res = false;
	
	if(hour > t.hour)
	{
		res = true;
		
	}else if(hour == t.hour)
	{
		if(min > t.min)
		{
			res = true;
			
		}else if(min == t.min)
		{
			if(sec > t.sec)
			{
				res = true;
			}
		}
	}
	
	return res;
}
	
bool TTime::operator<(const TTime &t) const
{
	bool res = false;
	
	if(hour < t.hour)
	{
		res = true;
		
	}else if(hour == t.hour)
	{
		if(min < t.min)
		{
			res = true;
			
		}else if(min == t.min)
		{
			if(sec < t.sec)
			{
				res = true;
			}
		}
	}
	
	return res;
}

ostream &operator<<(ostream &os, const TSubtitle &s)
{
	os << SUBT_FIRST;
	os << s.id << SUBT_SEPARATION << s.text << SUBT_SEPARATION << s.GetSTime('s');
	os << SUBT_LAST;

	return os;
}

TSubtitle::TSubtitle(void)
{
	id = -1;
	text = "SUBTITLE ERROR";
	
}

TSubtitle::TSubtitle( int sec, int min, int h): start(sec, min, h)
{
	id = -1;
		
}


TSubtitle::TSubtitle( string text, int sec, int min, int h) : start(sec , min ,h)
{
	this->id = -1;
	this->text = text;
	
}


TSubtitle::TSubtitle(const TSubtitle &s): start(s.start), finish(s.finish)
{
	id = s.id;
	this->text = s.text;
	
}


TSubtitle::~TSubtitle(void)
{
}


TSubtitle &TSubtitle::operator=(const TSubtitle &s)
{
	if(this != &s)
	{
		id = s.id;
		text = s.text;
	
		start = s.start;
		finish = s.finish;
	}

	return (*this);
}

void TSubtitle::SetText(string new_text)
{
	text = new_text;
}

void TSubtitle::SetID(int iD)
{
	id = iD;
}

bool TSubtitle::operator==(const TSubtitle &s) const
{
	return (text == s.text &&
			start == s.start &&
			finish == s.finish);
}

bool TSubtitle::operator!=(const TSubtitle &s) const
{
	return (text != s.text &&
			start != s.start &&
			finish != s.finish);
}

void TSubtitle::SetSTime(int sec, int min, int h)
{
	start.SetTime(sec, min , h);
}

void TSubtitle::SetFTime(int sec, int min, int h)
{
	finish.SetTime(sec, min, h);
}

int TSubtitle::GetID(void) const
{
	return id;
}

string TSubtitle::GetText(void) const
{
	return text;
}

int TSubtitle::GetSTime(char c) const
{

	switch (c)
	{
		case 's':
			return start.GetSec();
		case 'm':
			return start.GetMin();
		case 'h':
			return start.GetHour();
	}
}

int TSubtitle::GetFTime(char c) const
{

	switch (c)
	{
		case 's':
			return finish.GetSec();
		case 'm':
			return finish.GetMin();
		case 'h':
			return finish.GetHour();
	}
}

bool TSubtitle::operator<(const TSubtitle &s) const
{
	return (start < s.start);
}

bool TSubtitle::operator>(const TSubtitle &s) const
{
	return (start > s.start);
}

/*

profile TSubtitle::GetProfile(void) const
{

	return pro;
}
*/

